<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ showList.length }}</strong></span
    >
    <ul @click="changeSel" class="filters">
      <!-- 给 a 链接设置状态，方便操作 -->
      <li>
        <a
          @click="isSel = 'all'"
          :class="{ selected: isSel == 'all' }"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          @click="isSel = 'no'"
          :class="{ selected: isSel == 'no' }"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          @click="isSel = 'yes'"
          :class="{ selected: isSel == 'yes' }"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button @click="clearDone" class="clear-completed">清除已完成</button>
  </footer>
</template>

<script>
// 导入辅助函数
import { mapState, mapMutations, mapGetters } from 'vuex'

export default {
  computed: {
    ...mapState(['list']),
    ...mapGetters(['showList'])
  },
  data () {
    return {
      isSel: 'all' // 给 a 链接设置一个状态
    }
  },
  methods: {
    // 映射 isSel 状态 和 清除已完成的方法
    ...mapMutations(['isSelChange', 'clearIsDone']),
    changeSel () {
      this.isSelChange(this.isSel)
    },
    clearDone () {
      // 清除已完成
      this.clearIsDone()
    }
  }
}
</script>
